@extends("admin.common.admin")

<title>添加管理员 - 管理员管理 - H-ui.admin v3.1</title>
@section("cnt")
    <nav class="breadcrumb">
        <i class="Hui-iconfont">&#xe67f;</i>
        首页
        <span class="c-gray en">&gt;</span>
        角色修改
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" >
            <i class="Hui-iconfont">&#xe68f;</i>
        </a>
    </nav>
    <article class="page-container">
        @include("admin.common.msg")
        <form class="form form-horizontal" id="form-role-add" method="post" action="{{ route("admin.role.update",["id" => $list["id"]]) }}">
            @csrf
            @method("PUT")
            <div class="row cl">
                <label class="form-label col-xs-4 col-sm-3"><span class="c-red">*</span>用户名：</label>
                <div class="formControls col-xs-8 col-sm-9">
                    <input type="text" class="input-text" value="{{ $list["name"] }}" placeholder="" id="name" name="name">
                </div>
            </div>
            <div class="row cl">
                <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                    <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;">
                </div>
            </div>
        </form>
    </article>
@endsection
@section("js")
    <script type="text/javascript">
        // 获取id
        let id = {{ $list["id"] }};

        $(function(){
            $("#form-role-add").validate({
                rules:{
                    name:{
                        required:true,
                        minlength:2
                    },
                },
                onkeyup:false,
                success:"valid",
                submitHandler:function(form){
                    // 获取url路径
                    let url =$(form).attr("action");
                    // 获取表单数据
                    let FormData = $(form).serialize();
                    // 发送请求
                    $.post(url,FormData,ret=> {
                        // 使用dow操作对里面的内容进行刷新
                        parent.window.document.querySelector("#name_"+id).innerHTML = ret.data.name;
                        // 关闭弹窗
                        parent.layer.close(parent.layer.getFrameIndex(window.name));

                    })
                }
            });
        });
    </script>
@endsection
